/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.edu.unicen.twitter.suggest.backend.dtos;

import ar.edu.unicen.twitter.suggest.commons.dtos.Usuario;
import ar.edu.unicen.twitter.suggest.commons.tools.CollectionsOperations;
import java.io.Serializable;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 *
 * Clase contenedora, posee tres campos, referencias a otros objetos exceptuando
 * por el id, los campos restantes son lazy (pueden no conocerse aun, o bien
 * conocerse pero no haberse recuperado de la BD)
 *
 */
public class UsuarioDataset extends UsuarioDatasetAbstracto implements Serializable {

    private static final long serialVersionUID = 8634986793341581317L;
    private int[] followShortIds = null;
    private int[] followerShortIds = null;
    private int followCount = 0;
    private int followerCount = 0;
    List<TweetApi> tw = null;
    int tweetCount;
    String screenName;

    public UsuarioDataset(long id2) {
        super(id2);
        this.screenName = "u" + id2;
    }

    @Override
    public List<TweetApi> getTweets() {
        return getTw();
    }

    @Override
    public int getFollowsCount() {
        return followCount;
    }

    public void setFollowsCount(int count) {
        followCount = count;
    }

    public void setFollowersCount(int count) {
        followerCount = count;

    }

    @Override
    public int getFollowersCount() {
        return followerCount;
    }

    @Override
    public int getTweetsCount() {
        return tweetCount;
    }

    @Override
    public String getScreenName() {
        return screenName;
    }

    @Override
    public boolean equals(Object o1) {
        if (o1 instanceof Usuario && id == ((Usuario) o1).getId()) {
            return true;
        }
        return false;
    }

    @Override
    public long getId() {
        return id;
    }

    @Override
    public int hashCode() {
        return Usuario.calculateHashCode(id);
    }

    @Override
    public String toString() {
        return "[" + id + "]" + "(" + screenName + "):" + getMentions() + "m, " + getScore() + "scm " + getFollowsCount() + "fws, " + getFollowersCount() + "fwrs, ";
    }

    @Override
    public boolean isProtected() {
        return false;
    }

//hibernate
    UsuarioDataset() {
        super(0);
    }

    public UsuarioDataset(long id , int followersCount, int followsCount) {
        super(id);
        this.followerCount = followersCount;
        this.followCount = followsCount;
        this.screenName = "u" + id;
    }

    void setId(long id) {
        this.id = id;
    }

    List<TweetApi> getTw() {
        return tw;
    }

    void setTw(List<TweetApi> tweets) {
        this.tw = tweets;
    }

    @Override
    public int[] getFollowersShortIds() {
        return followerShortIds;
    }

    @Override
    public int[] getFollowsShortIds() {
        return followShortIds;
    }
    public void setFollowersShortIds(int[] ids) {
        followerShortIds = ids;
        if (ids != null) {
            this.followerCount = ids.length;
        } else {
            this.followerCount = 0;
        }
    }
    public void setFollowsShortIds(int[] ids) {
        this.followShortIds = ids;
        if (ids != null) {
            this.followCount = ids.length;
        } else {
            this.followCount = 0;
        }
    }

    @Override
    public Collection<Usuario> getFollowers() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Collection<Usuario> getFollows() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Set<Integer> getFollowSet() {
        return CollectionsOperations.getSet(followShortIds);
    }

    public void setFollowSet(Set<Integer> followSet) {
        followShortIds = CollectionsOperations.getIdShortArray(followSet);
    }

    @Override
    public Set<Integer> getFollowerSet() {
        return CollectionsOperations.getSet(followerShortIds);
    }

    public void setFollowerSet(Set<Integer> followerSet) {
        followerShortIds = CollectionsOperations.getIdShortArray(followerSet);
    }

    @Override
    public long[] getFollowersIds() {
        return CollectionsOperations.getIdArray(followerShortIds);
    }

    @Override
    public long[] getFollowsIds() {
        return CollectionsOperations.getIdArray(followShortIds);
    }
}
